import service from '@/utils/axios';
import { IResponseType, PageRO, PageVO, success } from '@/api/common';
import { SignVO, User, UserVO } from './user';
import { UserCreateRO } from '@/api/auth/auth';

export const sign = () => {
    return service<IResponseType<void>>({
        url: '/sign/on',
        method: 'get'
    }).then((d) => success(d, '签到成功'));
};

export const getSign = () => {
    return service<IResponseType<SignVO>>({
        url: '/sign/info',
        method: 'get'
    });
};

export const getUserInfo = () => {
    return service<IResponseType<UserVO>>({
        url: '/user/info',
        method: 'get'
    });
};

export const getUserPage = (pageRO: PageRO) => {
    return service<IResponseType<PageVO<UserVO>>>({
        url: '/user/page',
        method: 'post',
        data: pageRO
    });
};

export const create = (data: UserCreateRO) => {
    return service<IResponseType<void>>({
        url: '/user/create',
        method: 'post',
        data
    });
};

export const remove = (id: string) => {
    return service<IResponseType<void>>({
        url: '/user/remove/' + id,
        method: 'post'
    });
};

export const reset = (id: string) => {
    return service<IResponseType<void>>({
        url: '/user/reset/' + id,
        method: 'get'
    });
};

export const edit = async (data: User) => {
    return service<IResponseType<void>>({
        url: '/user/edit',
        method: 'post',
        data
    }).then((d) => success(d, '修改成功'));
};
